package it.datagraf.formazione.hellostruts.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class RedirigiUtenti extends Action {
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		if(request.isUserInRole("ROLE_cv.owner"))
			return mapping.findForward("owner");
		
		if(request.isUserInRole("ROLE_cv.guest"))
		{
			return mapping.findForward("admin");
		}
		if(request.isUserInRole("ROLE_cv.master"))
		{
			request.setAttribute("admin", "true");
			return mapping.findForward("admin");
		}
		//da fare gli altri if per i forward alle home di guest e admin 
		
		return null;
	}

}